package com.societyGames.flashForms
{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;

public class SingleItemContainer extends Sprite
{
  protected var _item:DisplayObject;

  public function get item():DisplayObject
  {
    return this._item;
  }

  public function set item(value:DisplayObject):void
  {
    if (this._item != value)
    {
      var changeSize:IChangeSize;
      //Remove the old one.
      if (this._item != null)
      {
        changeSize = this._item as IChangeSize;
        if (changeSize != null)
        {
          changeSize.sizeChangedEventObject.removeEventListener(childSizeChangedHandler);
        }
        this.removeChild(this._item);
      }
      this._item = value;
      //Deal with the new one.
      if (this._item != null)
      {
        changeSize = this._item as IChangeSize;
        if (changeSize != null)
        {
          changeSize.sizeChangedEventObject.addEventListener(childSizeChangedHandler);
        }
        this.addChild(this._item);
      }
      childSizeChangedHandler(null);
    }
  }

  /**
   * What the container should do if the child size changes.
   **/
  protected function childSizeChangedHandler(event:Event):void
  {
  }
}
}